# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-warnings_logger
pkgver=0.1.1
_commit=42ad623a7a0698f61a217b2fb24cce72b6bc3023
pkgrel=3
pkgdesc='Easily log warnings in your gems'
arch=(any)
url='https://github.com/mcmire/warnings_logger'
license=(MIT)
depends=(ruby)
makedepends=(git)
checkdepends=(ruby-pry-byebug ruby-rake ruby-rspec ruby-snowglobe ruby-rubocop)
options=(!emptydirs)
source=(git+https://github.com/mcmire/warnings_logger.git#commit=$_commit)
sha256sums=('SKIP')

prepare() {
  cd warnings_logger
  sed -i '/super_diff/d' Gemfile
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd warnings_logger
  gem build warnings_logger.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    warnings_logger-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd warnings_logger
  # https://github.com/mcmire/warnings_logger/issues/1
  GEM_HOME="tmp_install/$_gemdir" rake || echo "Tests failed"
}

package() {
  cd warnings_logger
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}
